﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MapEditor
{
    public partial class frmEdit : Form
    {
        private int _mapwidth;
        private int _mapheight;


        public int MapWidth
        {
            get
            {
                return _mapwidth;
            }
            set
            {
                _mapwidth = value;
                txtWidth.Text = _mapwidth.ToString();
            }
        }

        public int MapHeight
        {
            get
            {
                return _mapheight;
            }
            set
            {
                _mapheight = value;
                txtHeight.Text = _mapheight.ToString();
            }
        }

        public frmEdit(int mapwidth, int mapheight)
        {
            InitializeComponent();
            txtWidth.Text = mapwidth.ToString();
            txtHeight.Text = mapheight.ToString();
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            lblError.Visible = false;
            int i = 0;
            int j = 0;
            if (!Int32.TryParse(txtWidth.Text, out i) || !Int32.TryParse(txtHeight.Text, out j))
            {
                lblError.Visible = true;
                return;
            }

            if (Convert.ToInt32(txtWidth.Text) <= 0 || Convert.ToInt32(txtHeight.Text) <= 0)
            {
                lblError.Visible = true;
                return;
            }


            MapWidth = Convert.ToInt32(txtWidth.Text);
            MapHeight = Convert.ToInt32(txtHeight.Text);
            this.DialogResult = DialogResult.OK;
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
        }

        private void frmEdit_Load(object sender, EventArgs e)
        {

        }
    }
}
